package cn.tedu.charging.account.dao.persist.repository.impl;

import cn.tedu.charging.account.dao.persist.mappers.UserMapper;
import cn.tedu.charging.account.dao.persist.repository.IUserRepository;
import cn.tedu.charging.account.pojo.entity.User;
import cn.tedu.charging.account.pojo.param.UserAddNewParam;
import cn.tedu.charging.account.pojo.vo.UserStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 处理用户数据的存储库实现类
 *
 * @author java@tedu.cn
 * @version 1.0
 */
@Slf4j
@Repository
public class UserRepositoryImpl implements IUserRepository {

    @Autowired
    private UserMapper userMapper;

    public UserRepositoryImpl() {
        log.info("创建存储库对象：UserRepositoryImpl");
    }

    @Override
    public int insert(UserAddNewParam userAddNewParam) {
        log.debug("开始执行【插入用户】的数据访问，参数：{}", userAddNewParam);
        User user = new User();
        BeanUtils.copyProperties(userAddNewParam, user);
        int insert = userMapper.insert(user);
        BeanUtils.copyProperties(user, userAddNewParam);
        return insert;
    }

    @Override
    public int deleteById(String id) {
        log.debug("开始执行【根据ID删除用户】的数据访问，参数：{}", id);
        return userMapper.deleteById(id);
    }

    @Override
    public int updateById(User user) {
        log.debug("开始执行【更新用户】的数据访问，参数：{}", user);
        return userMapper.updateById(user);
    }

    @Override
    public UserStandardVO countByPhone(String phone) {
        log.debug("开始执行【根据用户名统计用户的数量】的数据访问，参数：{}", phone);
        UserStandardVO userStandardVO = userMapper.countByPhone(phone);
        return userStandardVO;
    }

    @Override
    public UserStandardVO selectByOpenId(String openId) {
        log.debug("开始执行【根据openId统计用户的数据】的数据访问，参数：{}", openId);
        UserStandardVO userStandardVO = userMapper.countByOpenId(openId);
        return userStandardVO;
    }


}
